import {Injectable } from '@angular/core';
import * as Parse from "parse";
(Parse as any).serverURL = "http://metapunk.cn:9999/parse"
Parse.initialize("dev")

@Injectable({
  providedIn: 'root'
})
export class PlayLppService {
  ModelList1 :any[] = [];
  clickDiv: boolean = false;
  clickDiv1: boolean = false;
  previousPage!: string;
  activeNavItem: number = 0 ;
  activeNavItem_: any = 0;
  activeNavItem_1: any = 0;
  the_proportion:string ="1:1"
  the_width_heigth:string = "512x512"
  options1 = [ '1:1' , '2:3' ,'3:4' ,'9:16' ,'3:2' ,'4:3' ,'16:9']
  options2 =[
    ['512x512' ,'768x768' ,'1024x1024' ],
    ['512x768' ,'768x1152'],
    ['576x768' ,'768x1024'],
    ['504x896' ,'720x1280'],
    ['768x512' ,'1152x768'],
    ['768x576' ,'1024x768'],
    ['896x504' ,'1280x720'],
  ] ;
  thIndex = 0;
  MyModel :any[]=[];

  constructor() { }
  getmodellist(){
    this.previousPage = document.referrer;
    const ModelList = Parse.Object.extend("ModelList");
    const query = new Parse.Query(ModelList);
    query.find().then((results) => {
      results.forEach((ModelList) => {
        const ModelSrc = ModelList.get("src");
        const ModelType = ModelList.get("type");
        const ModelName = ModelList.get("name");
        const ModelDetsil = ModelList.get("detail");
        const wordObject = {
          type :ModelType,
          modelsrc : ModelSrc,
          name: ModelName,
          detail : ModelDetsil,
        };
        this.ModelList1.push(wordObject);
        // console.log(this.ModelList1);
        
      });
    }).catch((error) => {
      console.error("Error querying DictionaryWord class:", error);
    });



  }
  
  returnToPreviousPage() {
    const previousPage = localStorage.getItem('previousPage');
    // console.log(previousPage);
    // this.path();

    console.log(this.activeNavItem_);
    
    if (previousPage) {
      history.back(); // 返回上一页，不刷新页面
    } else {
      window.location.href = "/pipi/home";
    }
  }
  choose(){
    const that =this
    const chooseli1_ = document.getElementById("chooseli1");
    const chooseli2_ = document.getElementById("chooseli2");
    let chooseli1 = <HTMLSelectElement>chooseli1_; 
    let chooseli2 = <HTMLSelectElement>chooseli2_; 
    for(var i = 0; i < this.options1.length; i++) {
      chooseli1.options.add(new Option(this.options1[i]));
    }
    chooseli1.onchange = function getProvince() {
      that.thIndex = chooseli1.selectedIndex;
      chooseli2.options.length = 0;
      that.the_proportion = chooseli1.options[chooseli1.selectedIndex].value
      console.log(chooseli1.options[chooseli1.selectedIndex].value);
      if(that.thIndex > -1) {
          for(var i = 0; i < that.options2[that.thIndex].length; i++) {
            chooseli2.options.add(new Option(that.options2[that.thIndex][i]));
          } 
          that.the_width_heigth = chooseli2.options[chooseli2.selectedIndex].value
          console.log(chooseli2.options[chooseli2.selectedIndex].value);
      }
    }
    chooseli2.onchange = function getProvince() {
      that.the_width_heigth = chooseli2.options[chooseli2.selectedIndex].value
      console.log(chooseli2.options[chooseli2.selectedIndex].value);
      
    }
  }
  

}